package com.danger.Presenter;

import android.content.Context;

import com.danger.Model.action.MyObjectInfoDetailModel;
import com.danger.Model.action.MyObjectInfoDetailModelImpl;
import com.danger.Model.bean.ObjectInfo;
import com.danger.Model.listener.OnDeleteListener;
import com.danger.Model.listener.OnGetObjectInfoListener;
import com.danger.View.MyObjectDetailView;

/**
 * Created by danger on 2016/3/31.
 */
public class MyObjectInfoDetailPresenterImpl implements MyObjectInfoDetailPresenter {

    private Context context;
    private MyObjectInfoDetailModel myObjectInfoDetailModel;
    private MyObjectDetailView myObjectDetailView;

    public MyObjectInfoDetailPresenterImpl(Context context, MyObjectDetailView myObjectDetailView) {
        this.context = context;
        this.myObjectDetailView = myObjectDetailView;
        myObjectInfoDetailModel = new MyObjectInfoDetailModelImpl(context);
    }

    @Override
    public void share() {
        String content = myObjectDetailView.getShareContent();
        String url = myObjectDetailView.getShareImageUrl();
        myObjectDetailView.showSuccess("分享", null);
        myObjectInfoDetailModel.shareMyObjectInfo(content, url);
    }

    @Override
    public void delete(String id) {
        myObjectDetailView.showDialog("delete");
        myObjectInfoDetailModel.deleteMyObjectInfo(id, new OnDeleteListener() {
            @Override
            public void onSuccess() {
                myObjectDetailView.hideDialog();
                myObjectDetailView.showSuccess("删除成功", null);
                myObjectDetailView.back();
            }

            @Override
            public void onError(String s) {
                myObjectDetailView.hideDialog();
                myObjectDetailView.showError("删除失败:" + s);
            }
        });
    }

    @Override
    public void toModify() {
        myObjectDetailView.toModify();
    }
}
